package com.atguigu.educms.controller;


import com.atguigu.common.R;
import com.atguigu.educms.entity.CmsContactInfo;
import com.atguigu.educms.service.CmsContactInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 联系信息 前端控制器
 * </p>
 *
 * @author Panghl
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/educms/cms-contact-info")
@Api(tags = {"联系信息"})
public class CmsContactInfoController {

    @Autowired
    private CmsContactInfoService contactInfoService;

    @ApiOperation(value = "获取联系信息")
    @GetMapping("/get")
    public R get() {
        CmsContactInfo contactInfo = contactInfoService.getContact();
        return R.ok().data("contactInfo", contactInfo);
    }

    @ApiOperation(value = "修改联系信息")
    @PostMapping("/edit")
    public R edit(@RequestBody CmsContactInfo cmsContactInfo) {
        try {
            if (StringUtils.isEmpty(cmsContactInfo.getId())) {
                contactInfoService.save(cmsContactInfo);
            } else {
                contactInfoService.updateById(cmsContactInfo);
            }
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

}
